from pathlib import Path

# 创建文件夹（如果文件夹不存在）
folder_path = Path("test_folder")
folder_path.mkdir(parents=True, exist_ok=True)

# 在文件夹中创建文件
file_path = folder_path / "example.txt"
with file_path.open("w") as file:
    file.write("This file is inside a folder.\n")